package com.isn.util;

import java.io.Serializable;
import javax.persistence.EntityManager;
import com.isn.util.JPAUtil;

public class GenericoJPA implements Serializable{
	
	private static final long serialVersionUID = 1L;
	protected EntityManager em;

	public void createEM() {
		try {
			em = JPAUtil.getEmf().createEntityManager();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	public void releaseEM() {
		em.close();
	}

	public void beginTransaction() {
		em.getTransaction().begin();
	}

	public void endTransaction() {
		em.getTransaction().commit();
		releaseEM();
	}
	
	public void rollbackTransaction() {
		em.getTransaction().rollback();
		releaseEM();
	}
	
	public void flush() {
		em.flush();
	}	
}
